/* ozogfra 1a
 This file contains the main function
 along with the command line parser 
 and test code */

#include <iostream>
#include <vector>
#include <stdlib.h>
#include "code.h"

using namespace std;

void parseCL (int &codeLength, int &codeRange, int argc, char* arr[]) 
//Parses command line and determines whether or not
//to take CL arguments or read from STDIN.
//Afterwards it informs the user of the codeLength and codeRange
//This function assumes the CL arguments are valid ints
{

  if (argc < 3)
  {  
    printf ("Enter size of secret code: ");
    cin >> codeLength;
    printf ("Enter number of possible numbers in secret code: ");
    cin >> codeRange;
  }
  else 
  {
    //Convert CL args to ints
    codeLength = atoi(arr[1]);
    codeRange = atoi(arr[2]);
    printf ("There are %d numbers in the secret code, ", codeLength);
    printf ("which can be numbers 0 - %d\n", codeRange-1);
    printf ("Good luck!\n");
  } // end if

} //end parseCL
  
void loadSample(vector<int> &vector, const int codeLength, const int arr[]) 
//Load array of ints into the vector
{
  //Remove all elements from the vector
  vector.resize(0);

  //for each guess int , push into vector
  for (int idx = 0; idx < codeLength; idx++)
    vector.push_back(arr[idx]);

}

void testSecretCode (const int codeLength, const SecretCode &secret)
//Declares three sample guesses, 
//then shows the result of each sample guess 
{
  int correctDigits;
  int correctLocations;

  const int sample1[10] = {1, 3, 4, 1, 5, 5, 3, 9, 4, 5};
  const int sample2[10] = {4, 9, 8, 7, 6, 5, 4, 3, 2, 9};
  const int sample3[10] = {1, 1, 1, 0, 0, 0, 1, 1, 1, 1};
  
  //initialize guess with each sample and give results
  vector<int> guess(codeLength);

  //For each sample number
  for (int sampleNum = 1; sampleNum < 4; sampleNum++)
  {

    switch (sampleNum)
    {
    case 1:
      loadSample (guess, codeLength, sample1);
      break;
    case 2:
      loadSample (guess, codeLength, sample2);
      break;
    case 3:
      loadSample (guess, codeLength, sample3);
      break;
    }

    printf ("\nStarting new try...\n");
    secret.checkCorrect(guess, correctDigits, correctLocations);
    printf ("You have %d correct digits in the correct location\n", correctDigits);
    printf ("You have %d correct digits in the wrong location\n", correctLocations);
  }

} // end testSecretCode

int main (int argc, char* argv[]) 
{
  int codeRange, codeLength;
  parseCL(codeLength, codeRange, argc, argv);

  SecretCode secret(codeLength, codeRange);
  testSecretCode(codeLength, secret);

  return 0;
}
